package com.tsd.base.service.impl;

import com.tsd.base.dao.BaseExchangeRateLogMapper;
import com.tsd.base.entity.BaseExchangeRateLog;
import com.tsd.base.entity.BaseExchangeRateLogExt;
import com.tsd.base.service.BaseExchangeRateLogService;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：BaseExchangeRateLog 服务实现层
 *
 * @author zsy
 * @date 2020/12/29 15:22:59
 */
@Service
public class BaseExchangeRateLogServiceImpl extends BaseServiceImpl implements BaseExchangeRateLogService {

    @Resource
    private BaseExchangeRateLogMapper baseExchangeRateLogMapper;

    @Override
    public BaseExchangeRateLog getBaseExchangeRateLogById(Long id) throws Exception {
        return baseExchangeRateLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public BaseExchangeRateLogExt queryBySid(String sid) throws Exception {
        return baseExchangeRateLogMapper.selectBySid(sid);
    }

    @Override
    public void deleteBaseExchangeRateLog(Long id, SysUser opUser) throws Exception {
        BaseExchangeRateLog old = baseExchangeRateLogMapper.selectByPrimaryKey(id);
        super.checkEmpty(old, "该记录不存在");
        super.autoInjectBaseData(old, opUser, this.TYPE_DELETE);
        baseExchangeRateLogMapper.updateByPrimaryKeySelective(old);
    }

    @Override
    public void saveBaseExchangeRateLog(BaseExchangeRateLog record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            baseExchangeRateLogMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            baseExchangeRateLogMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<BaseExchangeRateLogExt> findBaseExchangeRateLogs(Map<String, Object> params, PageBean page) throws Exception {
        return baseExchangeRateLogMapper.selectByPage(params, page);
    }

    @Override
    public List<BaseExchangeRateLogExt> findBaseExchangeRateLogs(Map<String, Object> params) throws Exception {
        return baseExchangeRateLogMapper.selectByParams(params);
    }
}
